import 'dart:ui';

import 'package:bruno/bruno.dart';
import 'package:common/image/image_tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../theme/font.dart';

/// @description:
/// @author
/// @date: 2025-01-21 14:28:41
class WhatLookMeListPage extends StatelessWidget {
  const WhatLookMeListPage({Key? key, required this.categoryId}) : super(key: key);
  final int categoryId;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        children: [
          categoryId == 0 ? _buildHeaderWhtaLookMeWrapper() : _buildHeaderPrivacyItemWrapper(value: true),
          Expanded(
            child: ListView.separated(
              itemBuilder: (BuildContext context, int index) {
                return _buildItem(name: '', image: '', sex: index % 1);
              },
              separatorBuilder: (BuildContext context, int index) {
                return Divider(height: 0.5, color: const Color(0xFFEEEEEE).withOpacity(0), indent: 15, endIndent: 15);
              },
              itemCount: 10,
            ),
          ),
        ],
      ),
    );
  }

  Container _buildHeaderWhtaLookMeWrapper() {
    return Container(
      height: 70,
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      margin: EdgeInsets.symmetric(vertical: 10.h),
      child: Row(
        children: [
          Expanded(
            child: Container(
              alignment: Alignment.center,
              decoration:
                  BoxDecoration(color: const Color(0xFFF8F8F8), borderRadius: BorderRadius.all(Radius.circular(8.r))),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('今日访客', style: TextStyle(color: const Color(0xFF999999), fontSize: 14.sp)),
                  Text('200',
                      style:
                          TextStyle(color: const Color(0xFF25D4D0), fontSize: 20.sp, fontWeight: AppFontWeight.medium)),
                ],
              ),
            ),
          ),
          const SizedBox(width: 12),
          Expanded(
            child: Container(
              decoration:
                  BoxDecoration(color: const Color(0xFFF8F8F8), borderRadius: BorderRadius.all(Radius.circular(8.r))),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('总访客', style: TextStyle(color: const Color(0xFF999999), fontSize: 14.sp)),
                  Text('200',
                      style:
                          TextStyle(color: const Color(0xFF25D4D0), fontSize: 20.sp, fontWeight: AppFontWeight.medium)),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildItem({required String image, required String name, required int sex}) {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(horizontal: 16),
      child: Column(
        children: [
          Container(
            padding: const EdgeInsets.symmetric(vertical: 10),
            child: Row(
              children: [
                ImageView(
                    url: 'https://img.zcool.cn/community/01fd6e5821a7c1a84a0e282ba9dbf4.gif',
                    width: 50.w,
                    height: 50.w,
                    fit: BoxFit.cover,
                    type: ImageViewType.avater,
                    shape: BoxShape.circle),
                const SizedBox(width: 10),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        // const BlurText(text: '喵喵小姐'),
                        Text('喵喵小姐',
                            style: TextStyle(
                                color: const Color(0xFF333333), fontSize: 16.sp, fontWeight: AppFontWeight.medium)),
                        const SizedBox(width: 5),
                        Padding(
                          padding: const EdgeInsets.only(right: 10),
                          child: sex == 1
                              ? Image.asset('assets/app/images/world/user_sex_girl.png', height: 16.h)
                              : Image.asset('assets/app/images/world/user_sex_boy.png', height: 16.h),
                        ),
                      ],
                    ),
                    categoryId == 0
                        ? Text('Ta忍不住看了你 1次  刚刚', style: TextStyle(color: const Color(0xFF999999), fontSize: 13.sp))
                        : Text('你查看了Ta 1次  刚刚', style: TextStyle(color: const Color(0xFF999999), fontSize: 13.sp)),
                  ],
                ),
                const Spacer(),
                Text('共访问2次', style: TextStyle(color: const Color(0xFF25D4D0), fontSize: 13.sp)),
              ],
            ),
          ),
          // const Divider(color: Color(0xFFEEEEEE), height: 0.5, indent: 5, endIndent: 5)
        ],
      ),
    );
  }

  Widget _buildHeaderPrivacyItemWrapper({Function? action, bool value = false}) {
    return Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 15.w),
        child: Column(
          children: [
            Container(
              padding: const EdgeInsets.symmetric(vertical: 15),
              child: Row(
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text('隐身访问  ',
                              style: TextStyle(fontSize: 15.sp, color: Colors.black, fontWeight: FontWeight.w500)),
                          Image.asset('assets/app/images/mine/vip_icon.png', width: 44),
                        ],
                      ),
                      const SizedBox(height: 5),
                      Text('打开后对方将看不到你的访问足迹',
                          style:
                              TextStyle(fontSize: 12.sp, color: const Color(0xFF999999), fontWeight: FontWeight.w500)),
                    ],
                  ),
                  const Spacer(),
                  BrnSwitchButton(
                    value: value,
                    onChanged: (value) {
                      action?.call(value);
                    },
                  )
                ],
              ),
            ),
          ],
        ));
  }
}

class BlurText extends StatelessWidget {
  const BlurText({Key? key, required this.text}) : super(key: key);
  final String text;
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.amber,
      child: BackdropFilter(
        filter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0), // 控制模糊程度
        child: Text(text,
            style: TextStyle(
                color: const Color(0xFF333333),
                fontSize: 16.sp,
                fontWeight: AppFontWeight.medium) // 文字样式，使用白色以便在模糊背景上清晰可见
            ),
      ),
    );
  }
}

// class MosaicTextWidget extends StatelessWidget {
//   final String text;
//   final TextStyle style;
//   final double pixelSize; // 马赛克块的大小

//   const MosaicTextWidget({super.key, required this.text, required this.style, required this.pixelSize});

//   @override
//   Widget build(BuildContext context) {
//     return CustomPaint(
//       painter: MosaicTextPainter(text: text, style: style, pixelSize: pixelSize),
//       size: const Size(double.infinity, 50), // 根据需要调整大小
//     );
//   }
// }

// class MosaicTextPainter extends CustomPainter {
//   final String text;
//   final TextStyle style;
//   final double pixelSize; // 马赛克块的大小

//   MosaicTextPainter({required this.text, required this.style, required this.pixelSize});

//   @override
//   void paint(Canvas canvas, Size size) {
//     final textSpan = TextSpan(text: text, style: style);
//     final textPainter = TextPainter(text: textSpan, textDirection: TextDirection.ltr);
//     textPainter.layout();

//     final offset = Offset(0.0, (size.height - textPainter.height) / 2);
//     textPainter.paint(canvas, offset);

//     // 马赛克处理
//     final paint = Paint();
//     final textBounds = textPainter.getOffsetForPlaceholders(textSpan).expand((rect) => rect).shift(offset);
//     final blockWidth = pixelSize;
//     final blockHeight = pixelSize;
//     for (var x = textBounds.left.floor(); x < textBounds.right; x += blockWidth) {
//       for (var y = textBounds.top.floor(); y < textBounds.bottom; y += blockHeight) {
//         final rect = Rect.fromLTWH(x.toDouble(), y.toDouble(), blockWidth, blockHeight);
//         paint.color = Colors.black; // 马赛克颜色
//         canvas.drawRect(rect, paint);
//       }
//     }
//   }

//   @override
//   bool shouldRepaint(covariant CustomPainter oldDelegate) {
//     return true; // 或者根据需要比较具体属性
//   }
// }
